﻿//地形服务
function TerrainService(layerInfo) {
    var TerrainService = new Object;
    TerrainService.id = layerInfo.hasOwnProperty("GUID") ? layerInfo.GUID : "";
    TerrainService.url = layerInfo.hasOwnProperty("URL") ? layerInfo.URL.replace("http://http://", "http://") : "";
    TerrainService.name = layerInfo.hasOwnProperty("NAME") ? layerInfo.NAME : "";
    TerrainService.servertype = layerInfo.hasOwnProperty("SERVERTYPE") ? layerInfo.SERVERTYPE : "";
    TerrainService.token = layerInfo.hasOwnProperty("TOKEN") ? layerInfo.TOKEN : "";
    TerrainService.CreateLayer = function() {
        var url = this.url;
        var id = this.id;
        var status = this.status;
        var token = this.token;
        var thisLayer = null;
        if (url != "") { //url不为空则加载指定地形服务
            thisLayer = new Cesium.CesiumTerrainProvider({
                url: url,
                id: id,
                //ellipsoid: viewer.scene.globe.ellipsoid
                isSct: false
            });
        } else if (token != "") { //url为空，token不为空，加载在线服务
            Cesium.Ion.defaultAccessToken = token;
            thisLayer = new Cesium.CesiumTerrainProvider({
                url: Cesium.IonResource.fromAssetId(1),
                id: id
            })
        }
        viewer.scene.terrainProvider = thisLayer;
        return thisLayer;
    }
    return TerrainService;
}